package simtester.server

import grails.test.mixin.TestFor
import org.junit.Test

/**
 * See the API for {@link grails.test.mixin.domain.DomainClassUnitTestMixin} for usage instructions
 */
@TestFor(ResultEntry)
class ResultEntryTests {

    @Test
    void createResultEntrySuccessfully() {
        def u = new User(username: 'testuser', password: 'pass')
        def testcase = new TestCase(name: 'tc1', owner: u, script: 'some script')
        def entry = new ResultEntry(testrun: new TestRun(status: 'running', testcase: testcase), user: 2, iteration: 5, entry: 'some log entry', level: 'info', timestamp: new Date())
       
        assert entry.validate()
    }
    
    @Test
    void createResultEntryWithoutRequiredFields() {
        def entry = new ResultEntry()
        assert !entry.validate()
        assert entry.errors.errorCount == 6
        assert 'nullable' in entry.errors['testrun'].codes
        assert 'nullable' in entry.errors['user'].codes
        assert 'nullable' in entry.errors['iteration'].codes
        assert 'nullable' in entry.errors['entry'].codes
        assert 'nullable' in entry.errors['level'].codes
        assert 'nullable' in entry.errors['timestamp'].codes
    }
}
